#include<bits/stdc++.h>
using namespace std;
int t;
int n,m,L,V;
int N[50][200010][5];
int M[50][200010];

int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    int op;
    for(int i=1;i<=t;i++){
       cin>>n>>m>>L>>V;
        op=0;
        for(int j=1;j<=n;j++){
            cin>>N[i][j][1]>>N[i][j][2]>>N[i][j][3];
            if(N[i][j][2]>V) op++;
        }
        int bn=0;
        for(int j=1;j<=m;j++){
            cin>>M[i][j];
            bn=max(bn,M[i][j]);
        }
        for(int j=1;j<=n;j++){
            if(N[i][j][2]>V&&N[i][j][1]<=bn) op++;
        }
        cout<<op<<" "<<m-1;
        cout<<endl;
    }


    return 0;
}
